//
//  UserDefaults.m
//  HTTP_request
//
//  Created by 姚琪 on 2017/12/8.
//  Copyright © 2017年 姚琪. All rights reserved.
//

#import "UserDefaults.h"

@implementation UserDefaults
#pragma mark  单例
+ (UserDefaults *)shareInstance {
    
    static UserDefaults *helper = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper = [[UserDefaults alloc] init];
    });
    return helper;
}

#pragma mark  同步
- (void)synchronize {
    
    [[NSUserDefaults standardUserDefaults] synchronize];
}

// 设置用户信息
#pragma mark  用户是否登录
- (void)setLoginState:(BOOL)isLogin {
    
    [[NSUserDefaults standardUserDefaults] setBool:isLogin forKey:@"isLogin"];
    [self synchronize];
}
#pragma mark  用户名
- (void)setUsername:(NSString *)username {
    
    [[NSUserDefaults standardUserDefaults] setObject:username forKey:@"username"];
    [self synchronize];
}
#pragma mark  用户密码
- (void)setPassword:(NSString *)password {
    
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:@"password"];
    [self synchronize];
}
#pragma mark  用户头像
- (void)setImage:(NSString *)image {
    
    [[NSUserDefaults standardUserDefaults] setObject:image forKey:@"image"];
    [self synchronize];
}

#pragma mark  用户id
- (void)setUserId:(NSString *)userId{
    
    [[NSUserDefaults standardUserDefaults] setObject:userId forKey:@"userId"];
    [self synchronize];
}

- (void)setReadingTime:(NSString *)readingTime{
    [[NSUserDefaults standardUserDefaults] setObject:readingTime forKey:@"readingTime"];
    [self synchronize];
}




//经纬度
- (void)setLongitude:(NSString *)longitude{
    [[NSUserDefaults standardUserDefaults] setObject:longitude forKey:@"longitude"];
    [self synchronize];
}
- (void)setLatitude:(NSString *)latitude{
    [[NSUserDefaults standardUserDefaults] setObject:latitude forKey:@"latitude"];
    [self synchronize];
}
- (void)setAddress:(NSString *)address{
    [[NSUserDefaults standardUserDefaults] setObject:address forKey:@"address"];
    [self synchronize];
}


- (NSString *)longitude{
     return [[NSUserDefaults standardUserDefaults] objectForKey:@"longitude"];
}
- (NSString *)latitude{
     return [[NSUserDefaults standardUserDefaults] objectForKey:@"latitude"];
}
- (NSString *)address{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"address"];
}

//店铺id
- (void)setShopId:(NSString *)shopId{
    [[NSUserDefaults standardUserDefaults] setObject:shopId forKey:@"shopId"];
    [self synchronize];
}
-(NSString *)shopId{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"shopId"];
}

#pragma mark  删除用户,也就是退出登录
- (void)deleteUser{
    NSUserDefaults *userDefatluts = [NSUserDefaults standardUserDefaults];
    NSDictionary *dictionary = [userDefatluts dictionaryRepresentation];
    for(NSString* key in [dictionary allKeys]){
        [userDefatluts removeObjectForKey:key];
        [userDefatluts synchronize];
    }
}

#pragma mark  获取用户信息
- (BOOL)loginState {
    
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"];
}

- (NSString *)username {
    
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
    
}
- (NSString *)password {
    return     [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
    
}
- (NSString *)image {
    return     [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
}

- (NSString *)userId {
    
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
}

-(NSString *)readingTime{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"readingTime"];
}



@end
